#include <iomanip>

#include "MRect.h"

MRect::MRect( float x, float y, float width, float height ) : 
								_point( MPoint( x, y ) ), 
								_size ( MSize( width, height ) )
{

}

MRect::MRect( MPoint point, MSize size ) : 
								_point( point ), 
								_size( size )
{
	
}

MRect::MRect( const MRect& rect ) :	
								_point( rect.point() ), 
								_size( rect.size() )
{

}

MRect& MRect::operator = ( const MRect& rect )
{ 
	_point = rect.point();
	_size = rect.size();
	return *this;
}

bool MRect::isPointInRect( MPoint point )
{
	return 
	( 
		point.x() >= _point.x() && 
		point.y() >= _point.y() &&
		point.x() <= _point.x() + _size.width() &&
		point.y() <= _point.y() + _size.height()
	) ? true : false;
}

MRect::~MRect()
{
}

void MRect::setX( float x )
{
	_point.setX( x );
}

float MRect::x() const
{
	return _point.x();
}

void MRect::setY( float y )
{
	_point.setY( y );
}

float MRect::y() const
{
	return _point.y();
}

void MRect::setWidth( float width )
{
	_size.setWidth( width );
}

float MRect::width() const
{
	return _size.width();
}

void MRect::setHeight( float height )
{
	_size.setHeight( height );
}

float MRect::height() const
{
	return _size.height();
}

void MRect::setPoint( MPoint point )
{
	_point = point;
}

MPoint MRect::point() const
{
	return _point;
}

void MRect::setSize( MSize size )
{
	_size = size;
}

MSize MRect::size() const
{
	return _size;
}

MRect MRect::operator + ( const MRect& rect )
{
	return MRect( point() + rect.point(), size() + rect.size() );
}

MRect& MRect::operator += ( const MRect& rect )
{
	setPoint( point() + rect.point() );
	setSize( size() + rect.size() );
	return *this;
}

MRect MRect::operator - ( const MRect& rect )
{
	return MRect( point() - rect.point(), size() - rect.size() );
}

MRect MRect::operator * ( const MRect& rect )
{
	return MRect( point() * rect.point(), size() * rect.size() );
}

MRect MRect::operator / ( const MRect& rect )
{
	return MRect( point() / rect.point(), size() / rect.size() );
}

bool MRect::operator > ( const MRect& rect )
{
	return ( _point > rect.point() || _size > rect.size() ) ? true : false;
}

std::ostream& operator << ( std::ostream& stream, const MRect& rect )
{
	stream << "MRect x = " << rect.x() << ", y = " << rect.y() << ", width = " << rect.width() << ", height = " << rect.height() << std::endl;
	return stream;
}

std::wofstream& operator << ( std::wofstream& stream, const MRect& rect )
{
	stream << "MRect x = " << rect.x() << ", y = " << rect.y() << ", width = " << rect.width() << ", height = " << rect.height() << std::endl;
	return stream;
}

MRect MRect::operator + ( float n )
{
	return MRect( width() + n, height() + n );
}

MRect MRect::operator - ( float n )
{
	return MRect( point() - n, size() - n );
}

MRect MRect::operator * ( float n )
{
	return MRect( point() * n, size() * n );
}

MRect MRect::operator / ( float n )
{
	return MRect( point() / n, size() / n );
}

bool MRect::operator > ( float n )
{
	return ( point() > n && size() > n ) ? true : false;
}

MRect abs( MRect& rect )
{
	return MRect( abs( rect.point() ), abs( rect.size() ) );
}